﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Leadtools.Codecs;
using Leadtools;
using System.Windows.Forms;
using System.Drawing;
using MINERP.NewProductBigPic.Properties;
using Leadtools.ImageProcessing;
using MINERP.COM;
using System.Drawing.Drawing2D;
using Leadtools.SpecialEffects;
using System.IO;
using MINERP.MODEL.NewProductBigPic;
using Leadtools.ColorConversion;

namespace MINERP.NewProductBigPic
{
    public partial class FrmBigPic
    {
        private bool _cutNoBarcode = false;
        private int BARCODEHEIDHT = 30;//条码的高度大约2mm
        const int COLORBLOCKWIDTH = 50;//色块的宽度
        const int BLOCKSEPARATION = 5;//各块之间的间距多少
         Bleed curBleed = DateTransfer.CurrentBleed;
        string _curCutFileFullPath="";
        /// <summary>
        /// 横向拼版竖向竖向生成并且裁切标记在前面
        /// </summary>
        /// <param name="board"></param>
        private void MakeBigPicH2VCutBeforePicOne(BoardInfo_ProductBigPic board)
        {
            curBleed = DateTransfer.CurrentBleed;
            int XExcursion = 0;//X坐标偏移量
            int i = 0;//当前正在操作的第几张图片
            string destFileName = board.BoardBaseInfo.PicPath;
            //int boardPixWidth = board.BoardBaseInfo.Length; //大图的长,相素
            //int BoardPixHeight = board.BoardBaseInfo.Height;//大图的高,相素
            int boardPixWidth = board.BoardBaseInfo.PixHeight; //大图的长,相素
            int BoardPixHeight = board.BoardBaseInfo.PixWidth;//大图的高,相素高宽互换

            //XExcursion = boardPixWidth;
            string errText = "";//错误信息
            List<PhotoPoint> listPhotoInfoForCut = new List<PhotoPoint>();//记录裁切版尺寸

            DateTransfer.IsAutoCut = board.BoardBaseInfo.IsAutoCut;

            UPTLab("正在生成：" + destFileName);
            UPTPgro(0, 0);
            try
            {
                //创建裁切标
                RasterCodecs.Startup();
                RasterCodecs codecs = new RasterCodecs();
               
                string aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", board.BoardBaseInfo.BoardId.ToString(), board.BoardBaseInfo.BoardId.ToString());
                RasterImage flagImageTop = codecs.Load(Application.StartupPath + "\\temBar.bmp");

                RasterImage flagImageBottom = codecs.Load(Application.StartupPath + "\\temBar.bmp");   ///       第二定位标记
                int offsetH = flagImageTop.Height;
                int destHegth = BoardPixHeight + offsetH;
                if (DateTransfer.TwoCutFlag)
                {
                    aaa = mai.CreateMarkPictureToFile(Convert.ToInt32((double)boardPixWidth / board.BoardBaseInfo.DPI * 2.54 * 100), board.BoardBaseInfo.DPI, Application.StartupPath + "\\temBar.bmp", "", "");
                    flagImageBottom = codecs.Load(Application.StartupPath + "\\temBar.bmp");
                    destHegth += offsetH;           // 第二定位标记给第二定位标记预留位置
                }
                //最终要输出的大图
                RasterImage destImage = new RasterImage(
                    RasterMemoryFlags.Conventional,
                    boardPixWidth,//+1保证最右边的框线可以出来
                    // BoardPixHeight + offsetH,
                   destHegth,
                    24,
                    RasterByteOrder.Bgr,
                    RasterViewPerspective.BottomLeft,
                    null,
                    IntPtr.Zero,
                    0);

                Color backColor = Settings.Default.BackColor;

                FillCommand fcommand = new FillCommand();
                //fcommand.Color = new RasterColor(128, 128, 128);
                fcommand.Color = new RasterColor(backColor);

                fcommand.Run(destImage);


                //粘贴裁切标记
                CombineFastCommand cfctop = new CombineFastCommand();
                cfctop.DestinationRectangle = new Rectangle(0, 0, flagImageTop.Width, flagImageTop.Height);
                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;
                cfctop.Run(flagImageTop);
                UPTLab("渲染大图框架成功");
                foreach (var picInfo in board.ListPhotos)
                {
                    if (picInfo.labelWidth != 0)
                    {
                        BARCODEHEIGHT = picInfo.labelWidth;
                    }
                    UPTLab("正在添加小图:" + picInfo.PhotoId);
                    try
                    {
                        #region 将所有的小图都粘贴到大图上
                        // 根据加急级别以及是否清空等确定字体的颜色
                        if (!File.Exists(picInfo.PicPath))
                        {
                            throw new Exception("文件未找到:" + picInfo.PicPath);
                        }
                        Color FontColor = GetFontColorByPhotoInfo(picInfo);

                        RasterImage smallPicImage = CreatePicImgV(picInfo, codecs, board);//   横向排竖向生产旋转竖向取反
                        DrowPicLine(ref smallPicImage, Color.Green);
                        int angel = 0;        ///旋转角度
                        PhotoBarCodeLocal barCodeLocal = PhotoBarCodeLocal.Bottom;    //条码所在方向
                        UPTLab("正在合成中间图");
                        RasterImage midImageTmp = CreateMidImgV(picInfo);//带有条码的中间图是竖版中间图
                        //UPTLab("小图片和带有条码的中间图生成成功");
                        #region 生成条码与文字信息,并将图片与条码贴在中间图上(midImage)


                        //是否有备注
                        if (picInfo.BarCodeStatus != (int)PhotoBarCodeStatus.NoBarCode)//有条码
                        {

                            Color backColorBarcode = new Color();

                            RasterImage barcodeImageTemp = CreateBarCodeImg(picInfo, midImageTmp, board, out backColorBarcode);//条码图片的临时图片
                           
                            RasterImage ColorImgBlock = GetColorBlockTextBackcolor(picInfo.OrderProductId);//色块,根据产品得到不同的色块
                            //codecs.Save(ColorImgBlock,@"e:\123.jpg",RasterImageFormat.Jpeg,24);

                            UPTLab("粘贴色块");
                            CombineFastCommand cfcBarcode1 = new CombineFastCommand();
                            cfcBarcode1.DestinationRectangle = new Rectangle(
                             0,
                             0,
                             barcodeImageTemp.Width,
                             barcodeImageTemp.Height);

                            cfcBarcode1.SourcePoint = Point.Empty;
                            cfcBarcode1.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;

                            cfcBarcode1.DestinationImage = barcodeImageTemp;
                            cfcBarcode1.Run(ColorImgBlock);


                            UPTLab("生成条码及文字");

                            #region 打印条码及文字信息
                            Graphics g = barcodeImageTemp.CreateGdiPlusGraphics().Graphics;//用来打印条码和文字
                            g.SmoothingMode = SmoothingMode.None;
                            SpecialEffectsProcessor processor = new SpecialEffectsProcessor();
                            int recX = ColorImgBlock.Width + 5, recY = -2;
                            string Barcode = "";
                            string nullBar = " ";
                            SizeF sizeF;
                           
                                recX += 20;
                                //Barcode = cifi.EAN13(picInfo.PhotoId.ToString());
                                //sizeF = gFont.MeasureString(Barcode, textBarFont13);
                                Barcode = "*" + picInfo.PhotoId + "*";
                                sizeF = gFont.MeasureString(Barcode, textBarFont);
                                BARCODEWIDTH = Convert.ToInt32(sizeF.Width / gFont.DpiX * barcodeImageTemp.XResolution) + 10;
                                nullBar = picInfo.PhotoId.ToString();
                           

                            //BARCODEWIDTH = ((int)sizeF.Width) + 2;//条码的宽度
                            //BARCODEWIDTH = Convert.ToInt16(sizeF.Width / gFont.DpiX * board.BoardBaseInfo.DPI)*2;
                            //色块就有50
                            //if (BARCODEWIDTH + COLORBLOCKWIDTH + 2 * BLOCKSEPARATION <= barcodeImageTemp.Width)//条码的长度会不会小于照片某片的长度
                            if (Settings.Default.SmallSizeToPrintBarCode * board.BoardBaseInfo.DPI < barcodeImageTemp.Width)
                            {
                                //打条码
                                Rectangle rc = new Rectangle(recX, recY, BARCODEWIDTH, BARCODEHEIDHT);
                                g.DrawString("*" + picInfo.PhotoId.ToString() + "*", textBarFont, Brushes.Black,
                                    recX, recY);
                                recX += BARCODEWIDTH;
                            }
                            else
                            {

                            }
                            //写其文字信息

                            recX += BLOCKSEPARATION;//条码与文字之间还需要加上一段间距
                            string productName = "";
                            string leftProduct = "";
                            picInfo.PhotoName = picInfo.PhotoName.TrimStart('\\');
                            int PIndex = picInfo.PhotoName.IndexOf('\\');
                            if (PIndex > 0)
                            {
                                productName = picInfo.PhotoName.Substring(0, PIndex);
                                leftProduct = picInfo.PhotoName.Substring(PIndex);
                            }
                            else
                            {
                                productName = picInfo.PhotoName;
                                leftProduct = "-";
                            }


                            string text = "";
                            try
                            {
                                text = GetBarCodeStringByCutsom(picInfo, board).Trim('\\');
                            }
                            catch
                            {

                            }
                            SizeF sizetextF = gFont.MeasureString(text, textFont);

                            StringFormat textFormat = new StringFormat();
                            textFormat.Alignment = StringAlignment.Near;
                            textFormat.LineAlignment = StringAlignment.Center;
                            textFormat.FormatFlags = StringFormatFlags.DisplayFormatControl | StringFormatFlags.NoWrap;

                            //textFormat.
                            Rectangle rcFont = new Rectangle(recX - 20, 2, barcodeImageTemp.Width - recX, BARCODEHEIDHT);


                            gFont.PageUnit = GraphicsUnit.Pixel;

                            string newText = text;
                            if (DateTransfer.TextAlignType == 0)//左
                            {
                                newText = text;
                            }
                            else if (DateTransfer.TextAlignType == 1)//右对齐
                            {
                                for (int m = 0; m < text.Length; m++)
                                {
                                    newText = text.Substring(m);

                                    SizeF sizenewtextF = gFont.MeasureString(newText, textFont, barcodeImageTemp.Width - recX, textFormat);

                                    if (sizenewtextF.Width <= (barcodeImageTemp.Width - recX) * gFont.DpiX / board.BoardBaseInfo.DPI)
                                    {
                                        break;
                                    }
                                }
                            }
                            else
                            {
                                newText = text;
                                textFormat.Alignment = StringAlignment.Center;
                                textFormat.LineAlignment = StringAlignment.Center;
                            }


                            g.PageUnit = GraphicsUnit.Pixel;
                            g.DrawString(newText, textFont, new SolidBrush(FontColor), rcFont, textFormat);


                            //codecs.Save(barcodeImageTemp, @"c:\\barcodeImageTemp.jpg", RasterImageFormat.Jpeg, 24);
                            ColorResolutionCommand command =
                               new ColorResolutionCommand(ColorResolutionCommandMode.InPlace, 24, RasterByteOrder.Bgr,
                                   RasterDitheringMethod.None, ColorResolutionCommandPaletteFlags.Optimized, null);
                            command.Run(barcodeImageTemp);
                            g.Dispose();
                            //gFont.Dispose();
                            ColorImgBlock.Dispose();//释放色块的资源
                            #endregion

                            UPTLab("正在粘贴图片");

                            #region 向中间图片mdiImageTemp图贴图片

                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            Rectangle barCodeRec, picRec;
                            ///注释：中间图以及原图竖版合成的
                            ///原图是旋转270度放置 中间图无方向 但是竖向的
                            ///条码的方向是针对中间图的跟照片原方向木有关系
                            ///越多左右方向0右1左 上下方向下0上1
                            if (picInfo.BarCodeStatus == (int)PhotoBarCodeStatus.TopOrBottom)
                            {
                                //竖版生成在竖方向相对于原方向的横方向
                                //条码备注在中间图的左右方向 
                                if (!picInfo.IsWhirl)
                                {
                                    //实际是在图的上下方向
                                    if (DateTransfer.RemarkInPicBottomOrTop == 0)
                                    {

                                        //旋转270度后右边边就是照片的下面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 270 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(smallPicImage.Width, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = PhotoBarCodeLocal.Right;
                                    }
                                    else//
                                    {
                                        //旋转270度后左边就是照片的上面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 90 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(barcodeImageTemp.Width, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = PhotoBarCodeLocal.Left;
                                    }
                                }
                                else
                                {
                                    //照片的实际方向横竖方向是没有变的
                                    //实际是在图的上下方向
                                    if (DateTransfer.RemarkInPicRightOrLeft == 0)
                                    {
                                        //右边就是照片的右面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 270 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(smallPicImage.Width, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = PhotoBarCodeLocal.Right;
                                    }
                                    else//左边就是照片的左边
                                    {
                                        //旋转270度后右边就是照片的上面
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 90 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(barcodeImageTemp.Width, 0, smallPicImage.Width, smallPicImage.Height);

                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = PhotoBarCodeLocal.Left;
                                    }
                                }


                            }
                            else  //0:条码在中间图的上下方向
                            {
                                if (!picInfo.IsWhirl)
                                {
                                    if (DateTransfer.RemarkInPicRightOrLeft == 0)
                                    {
                                        //右边就是打相对于照片的上面
                                        //barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, BARCODEHEIDHT);
                                        //picRec = new Rectangle(0, BARCODEHEIDHT, smallPicImage.Width, smallPicImage.Height);
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 180 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);
                                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = PhotoBarCodeLocal.Top;
                                    }
                                    else
                                    {
                                        //左边就是打相对于照片下面

                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, barcodeImageTemp.Height);
                                        barCodeLocal = PhotoBarCodeLocal.Bottom;
                                    }
                                }
                                else//旋转过
                                {
                                    if (DateTransfer.RemarkInPicBottomOrTop == 0)
                                    {



                                        picRec = new Rectangle(0, 0, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, smallPicImage.Height, barcodeImageTemp.Width, smallPicImage.Height);
                                        barCodeLocal = PhotoBarCodeLocal.Bottom;
                                    }
                                    else
                                    {
                                        RotateCommand rcBarcode = new RotateCommand();//旋转条码图片               
                                        rcBarcode.Angle = 180 * 100;
                                        rcBarcode.FillColor = new RasterColor(255, 255, 255);
                                        rcBarcode.Flags = RotateCommandFlags.Resize;
                                        rcBarcode.Run(barcodeImageTemp);

                                        picRec = new Rectangle(0, barcodeImageTemp.Height, smallPicImage.Width, smallPicImage.Height);
                                        barCodeRec = new Rectangle(0, 0, barcodeImageTemp.Width, smallPicImage.Height);
                                        barCodeLocal = PhotoBarCodeLocal.Top;

                                    }
                                }
                            }

                            CombineFastCommand cfcBarcode = new CombineFastCommand();
                            cfcBarcode.SourcePoint = Point.Empty;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.DestinationImage = midImageTmp;



                            cfcBarcode.DestinationRectangle = barCodeRec;
                            cfcBarcode.Run(barcodeImageTemp);

                            //UPTLab("贴图片");
                            //贴图片
                            cfcBarcode.DestinationRectangle = picRec;
                            cfcBarcode.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcBarcode.Run(smallPicImage);

                            barcodeImageTemp.Dispose();//释放条码(包含条码和文字信息)图片
                            #endregion

                        }
                        else//无条码
                        {
                            //向中间图片上贴图片
                            CombineFastCommand cfcCommand = new CombineFastCommand();
                            cfcCommand.DestinationRectangle = new Rectangle(
                                                                               0,
                                                                               0,
                                                                               smallPicImage.Width,
                                                                               smallPicImage.Height);
                            cfcCommand.SourcePoint = Point.Empty;
                            cfcCommand.DestinationImage = midImageTmp;
                            cfcCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                            cfcCommand.Run(smallPicImage);
                        }
                        #endregion

                        UPTLab("正在绘制中间图边框");
                        #region //给中间图画边框
                        if (Properties.Settings.Default.BoolPrintPhotoLine)
                        {
                            Graphics g2 = null;
                            try
                            {

                                DrowBordLine(ref midImageTmp);

                            }
                            catch (Exception Boardex)//如果添加边框出错就不添加
                            {
                                WriteLogForCheck.WriteLogFile(DateTime.Now.ToString() + "-----" + picInfo.PicPath + "添加边框时出错:" + Boardex.Message);
                                DrowBordLine(ref midImageTmp);

                            }
                            finally
                            {
                                if (g2 != null)
                                {
                                    g2.Dispose();
                                }
                            }
                        }
                        #endregion
                        UPTLab("正在粘贴图片:ID" + picInfo.PhotoId + ",照片" + picInfo.PicPath);
                        //将中间图(midImage,包括一张图片并画有条码信息)贴在大板上
                        int pointX;
                        int pointY;
                        try
                        {
                            pointX = picInfo.Location.X;
                            pointY = picInfo.Location.Y;
                        }
                        catch (Exception)
                        {
                            pointY = 0;
                            pointX = 0;
                        }
                        ///转换坐标
                        /// 
                        int picLocalX = pointY;
                        int picLocalY = pointX + offsetH;


                     
                        CombineFastCommand midCommand = new CombineFastCommand();
                        midCommand.DestinationRectangle = new Rectangle(
                             picLocalX,//在大图上的坐标
                            picLocalY,
                            midImageTmp.Width,//长和宽
                            midImageTmp.Height);
                        midCommand.SourcePoint = Point.Empty;
                        midCommand.DestinationImage = destImage;
                        midCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                        midCommand.Run(midImageTmp);
                        if (DateTransfer.IsAutoCut)//自动裁切模式IsTransverse 改为是否使用裁切选择项目
                        {
                            //计算裁切尺寸
                            //string mmX = (((double)pointY / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmy = (((double)pointX / board.BoardBaseInfo.DPI * 2.54 * 10)).ToString("0.0");
                            //string mmWidth = (((double)midImageTmp.Width / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            //string mmheight = (((double)midImageTmp.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0");
                            ////CommFile.WrtieText(mmX + "," + mmy + "," + mmWidth + "," + mmheight, destFileName.Substring(0, destFileName.LastIndexOf(".")) + ".txt");
                            //string strphotoInfo = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                            //listPhotoInfoForCut.Add(strphotoInfo);
                            PhotoPoint photoP = new PhotoPoint();
                            //photoP.X = pointY;                                                                                    //photoP.Y = pointX;
                            photoP.X = picLocalX;
                            photoP.Y = picLocalY - offsetH;
                            photoP.Width = midImageTmp.Width;
                            photoP.Height = midImageTmp.Height;
                            photoP.BarCodeLocal = barCodeLocal;

                            if (picInfo.IsWhirl)
                            {
                                photoP.Angle = 0;
                            }
                            else
                            {
                                photoP.Angle = 270;
                            }
                            //计算DXF宽高
                            if (!string.IsNullOrEmpty(picInfo.DXFFilePath))
                            {
                                //SmallERP.COM.DxfExtend.GetDxfInfo(picInfo.DXFContent);
                                //DxfObjecctInfo mindxfObjecctInfo =
                                //    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMIN");
                                //DxfObjecctInfo maxdxfObjecctInfo =
                                //    SmallERP.COM.DxfExtend.ListDXFObj.FirstOrDefault(p => p.KeyString == "$EXTMAX");
                                //DXFPointer maxPointer = DxfExtend.AlyseEXTVaue(maxdxfObjecctInfo.ContentList);
                                //DXFPointer minPointer = DxfExtend.AlyseEXTVaue(mindxfObjecctInfo.ContentList);
                                //photoP.DXFWidth = maxPointer.X - minPointer.X;
                                //photoP.DXFHeigth = maxPointer.Y - minPointer.Y;
                                photoP.DXFContent = picInfo.DXFContent;
                                photoP.DxfPath = picInfo.DXFFilePath;
                            }
                            else
                            {
                                photoP.DXFWidth = 0;
                                photoP.DXFHeigth = 0;
                                photoP.DXFContent = null;
                            }

                            listPhotoInfoForCut.Add(photoP);
                            if (XExcursion > photoP.X)
                            {
                                XExcursion = photoP.X;///居中偏移量
                            }
                        }
                        UPTLab("将中间图贴在大图上");
                        midImageTmp.Dispose();
                        smallPicImage.Dispose();
                        GC.Collect();

                        UPTPgro(board.ListPhotos.Count, ++i);//进度条                  
                        UPTLab("添加小图成功:" + picInfo.PhotoId);

                        #endregion 生成条码与文字信息
                    }
                    catch (Exception ex)
                    {
                        errText = picInfo.PicPath;
                        throw ex;
                    }
                }

                UPTLab("所有小图生成成功");
                codecs.Options.Jpeg.Save.CmpQualityFactorPredefined = CodecsCmpQualityFactorPredefined.PerfectQuality1;

                cfctop.DestinationRectangle = new Rectangle(0, destHegth - offsetH, flagImageBottom.Width, flagImageBottom.Height);
                cfctop.SourcePoint = Point.Empty;
                cfctop.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
                cfctop.DestinationImage = destImage;
                cfctop.Run(flagImageBottom);


               
                    if (board.ListPhotos.Count <= Properties.Settings.Default.MinAutoCut)
                    {
                        DateTransfer.IsAutoCut = false;
                    }
                    else
                    {
                        //不处理
                    }
                

                //写入文件 
                StringBuilder sbWriter = new StringBuilder();
                //sbWriter.AppendLine((((double)board.BoardBaseInfo.Height / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.Length / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.BoardBaseInfo.DPI);
                sbWriter.AppendLine((((double)board.BoardBaseInfo.PixHeight / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + (((double)board.BoardBaseInfo.PixWidth / board.BoardBaseInfo.DPI * 2.54 * 100)).ToString("0") + "," + board.BoardBaseInfo.PrintName);
                foreach (PhotoPoint pp in listPhotoInfoForCut)
                {

                   
                    int xVar = 0;
                    int yVar = 0;
                    int wVar = 0;

                    int hVar = 0;
                    int variable = Convert.ToInt32((double)BARCODEHEIDHT / board.BoardBaseInfo.DPI * 2.54 * 100);
                    if (_cutNoBarcode)
                    {
                        if (pp.BarCodeLocal == PhotoBarCodeLocal.Left)
                        {
                            xVar = variable;
                            wVar = -variable;
                        }
                        else if (pp.BarCodeLocal == PhotoBarCodeLocal.Right)
                        {
                            wVar = -variable;
                        }
                        else if (pp.BarCodeLocal == PhotoBarCodeLocal.Top)
                        {
                            yVar = variable;
                            hVar = -variable;
                        }
                        else if (pp.BarCodeLocal == PhotoBarCodeLocal.Bottom)
                        {
                            hVar = -variable;
                        }

                    }

                    int merginMMcCen = 0;
                    int merginMMWH = 0;
                    int merginMidWidth = 0;
                    int merginMidHeight = 0;
                    int merginRx = 0;
                    int merginRy = 0;
                    double chanePara = 1d / board.BoardBaseInfo.DPI * 2.54 * 100;
                    if (_cutNoBarcode)
                    {
                        if (curBleed.Type == 0)
                        {
                            merginRx = merginRy = Convert.ToInt32(curBleed.Value * 10);
                            //MerginMMWH = Convert.ToInt32((curBleed.Value*10*2);
                            merginMidWidth = merginMidHeight = Convert.ToInt32(curBleed.Value * 10 * 2); ;
                        }
                        else
                        {

                            //if (pp.Width >= pp.Height)
                            //{
                            //    //double h = pp.Height;
                            //    merginMidHeight = Convert.ToInt32(pp.Height * curBleed.Value / 100 * chanePara);
                            //    merginMidWidth = Convert.ToInt32(pp.Width * merginMidHeight / (pp.Height * chanePara));
                            //    //merginRx = merginMidWidth / 2;
                            //    //merginRy = merginMidHeight / 2;
                            //}
                            //else
                            //{
                            //    merginMidWidth = Convert.ToInt32(pp.Width * curBleed.Value / 100 * chanePara);
                            //    merginMidHeight = Convert.ToInt32(pp.Height * merginMidWidth / (pp.Width * chanePara));
                            //}
                            //merginRx = merginMidWidth / 2;
                            //merginRy = merginMidHeight / 2;

                            merginRx = Convert.ToInt32(pp.Width * curBleed.Value / 100 * chanePara);
                            merginRy = Convert.ToInt32(pp.Height * curBleed.Value / 100 * chanePara);
                            merginMidWidth = merginRx * 2;
                            merginMidHeight = merginRy * 2;
                        }
                        ;
                        if (pp.DXFContent != null)
                        {
                            merginRx = merginRy = merginMidWidth = merginMidHeight = 0;
                        }
                    }


                    string mmX = (((double)pp.X / board.BoardBaseInfo.DPI * 2.54 * 100 + merginRx + xVar)).ToString("0");
                    string mmy = (((double)pp.Y / board.BoardBaseInfo.DPI * 2.54 * 100 + merginRy + yVar)).ToString("0");
                    string mmWidth = (((double)pp.Width / board.BoardBaseInfo.DPI * 2.54 * 100 - merginMidWidth + wVar)).ToString("0");
                    string mmheight = (((double)pp.Height / board.BoardBaseInfo.DPI * 2.54 * 100 - merginMidHeight + hVar)).ToString("0");

                    string dxfFlag = "DXF";
                    string strWriter = "";
                    if (pp.DXFContent == null)
                    {
                        strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight;
                    }
                    else
                    {
                        string angleStr = pp.Angle.ToString();
                        string wScolar = "1";
                        string hScolar = "1";
                        int angleNum = pp.Angle / 90;
                        //if (angleNum % 2 == 0)
                        //{
                        //    wScolar = (Convert.ToDouble(mmWidth) / pp.DXFWidth / 10).ToString();
                        //    hScolar = (Convert.ToDouble(mmheight) / pp.DXFHeigth / 10).ToString();
                        //}
                        //else
                        //{
                        //    wScolar = (Convert.ToDouble(mmheight) / pp.DXFWidth / 10).ToString();
                        //    hScolar = (Convert.ToDouble(mmWidth) / pp.DXFHeigth / 10).ToString();
                        //}                                                                                                                                                                                                                                        
                        string dxfContent = Encoding.UTF8.GetString(pp.DXFContent).Replace("\r\n", "||");
                        //string dxfContent = NetDxfExtend.GetCutInfo(pp.DxfPath);                            
                        strWriter = mmX + "," + mmy + "," + mmWidth + "," + mmheight + "," + angleStr + "," + wScolar + "," +
                                    hScolar + "," + dxfFlag + "," + "[" + dxfContent + "]";
                    }
                    sbWriter.AppendLine(strWriter);

                }
                string FileName = destFileName.Substring(0, destFileName.LastIndexOf("@")) + ".txt"; ;
                if (File.Exists(FileName))
                {
                    File.Delete(FileName);
                }
                WrtieTextEn(sbWriter, FileName);
                //EncryptionAndSave(board.BoardBaseInfo.BoardId, sbWriter);
                UPTLab("判断目录是否存在");
                string strDir = destFileName.Substring(0, destFileName.LastIndexOf('\\'));
                DirectoryInfo di = new DirectoryInfo(strDir);
                if (!di.Exists)
                {
                    di.Create();
                }

                destImage.XResolution = board.BoardBaseInfo.DPI;
                destImage.YResolution = board.BoardBaseInfo.DPI;
                if (board.BoardBaseInfo.Sharpen > 0)//如果设置了税化值就进行锐化
                {
                    UPTLab("正在进行锐化处理...");
                    Leadtools.ImageProcessing.Effects.SharpenCommand command = new Leadtools.ImageProcessing.Effects.SharpenCommand();
                    command.Sharpness = board.BoardBaseInfo.Sharpen;
                    command.Run(destImage);
                }


                UPTLab("正在保存大图...");

                if (Settings.Default.AddIccByPs)//需要用PS加载ICC
                {
                    if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                    {
                        codecs.Save(destImage, strTempPath, RasterImageFormat.Jpeg, 24);
                    }
                    else
                    {
                        codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                    }

                }
                else//用LEADTOOLS加载ICC
                {
                    //处理旋转的问题
                    //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                    //{
                    //    UPTLab("正在竖向旋转90度...");
                    //    if (destImage.Width >= 18898 || destImage.Height >= 18898)//大于这个尺寸就用PS进行旋转
                    //    {
                    //        try
                    //        {
                    //            File.Delete(Application.StartupPath + "\\tem.jpg");
                    //        }
                    //        catch { }

                    //        codecs.Save(destImage, Application.StartupPath + "\\temBig.jpg", RasterImageFormat.Jpeg, 24);

                    //        PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                    //        myClass.DoRotate(Application.StartupPath + "\\temBig.jpg", Application.StartupPath + "\\tem.jpg", true, 90);
                    //        destImage = codecs.Load(Application.StartupPath + "\\tem.jpg");
                    //        File.Delete(Application.StartupPath + "\\temBig.jpg");
                    //    }
                    //    else
                    //    {
                    //        RotateCommand rc = new RotateCommand();
                    //        rc.Angle = 90 * 100;
                    //        rc.FillColor = new RasterColor(255, 255, 255);
                    //        rc.Flags = RotateCommandFlags.Resize|RotateCommandFlags.Bicubic;
                    //        rc.Run(destImage);
                    //    }

                    //}

                    switch (PicFormat)
                    {
                        case 0: codecs.Save(destImage, destFileName, RasterImageFormat.Jpeg, 24);
                            break;
                        case 1:
                            codecs.Save(destImage, destFileName, RasterImageFormat.Tif, 24);
                            break;
                    }

                    #region//指定转换配置文件(不通过ps加载ICC时用)
                    string colorSpace = Properties.Settings.Default.ColorSpace;
                    bool setColorSpace = Properties.Settings.Default.SetColorSpace;
                    string fname = Application.StartupPath + "\\SetSpaceTem.jpg";

                    int intRatate = 0;
                    //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90
                    //{
                    //    intRatate = 90;
                    //}
                    string strResult = string.Empty, strPicFormat;
                    if (setColorSpace)
                    {
                        try
                        {
                            File.Delete(Application.StartupPath + "\\SetSpaceTem.jpg");
                        }
                        catch
                        { }
                        codecs.Save(destImage, Application.StartupPath + "\\SetSpaceTem.jpg", RasterImageFormat.Jpeg, 24);
                        //PSICC.ClassIccClass myclass = new PSICC.ClassIccClass();

                        //switch (PicFormat)
                        //{
                        //    case 0: strPicFormat = "JPEG"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref  intRatate);

                        //        break;
                        //    case 1: strPicFormat = "TIFF"; strResult = myclass.DoIccUsm(fname, destFileName, true, false, "", false, 0, 0, 0, ref strPicFormat, ref colorSpace, ref intRatate);
                        //        break;
                        //}

                        psApp.AddICC(colorSpace, fname, destFileName);

                        if (strResult == destFileName)
                        {
                            UPTLab("成功转换配置文件:" + colorSpace);
                        }
                        else
                        {
                            //加载ICC失败
                            UPTLab("转换配置文件失败!" + strResult);
                            throw new Exception("转换配置文件失败!" + strResult);
                        }
                    }
                    #endregion
                }



                #region //写入ICC文件

                UPTLab("正在加载ICC文件..." + board.BoardBaseInfo.IccPath);
                if (!string.IsNullOrEmpty(board.BoardBaseInfo.IccPath) && board.BoardBaseInfo.IccPath != @"\\")
                {
                    if (Properties.Settings.Default.AddIccByPs)//需要用PS加载ICC
                    {
                        try
                        {
                            //iCC的名称，需要与PS中的一致
                            string iccName = board.BoardBaseInfo.IccPath.Substring(board.BoardBaseInfo.IccPath.LastIndexOf(@"\") + 1);
                            iccName = iccName.Substring(0, iccName.IndexOf("."));
                            try
                            {
                                File.Delete(destFileName);//如果以前生成过图片，则删除已生成的
                            }
                            catch { }

                            //PSICC.ClassIccClass myClass = new PSICC.ClassIccClass();
                            string strResult = string.Empty, strPicFormat;
                            string strInputIcc = Settings.Default.ColorSpace;
                            //string strInputIcc = "ColorMatch RGB";
                            //string strInputIcc = "sRGB IEC61966-2.1";
                            int intRatate = 0;
                            //if (board.BoardBaseInfo.IsTransverse)//竖向的就转90竖版生成后不需要旋转
                            //    intRatate = -90;

                            //switch (PicFormat)
                            //{
                            //    case 0: strPicFormat = "JPEG"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref  intRatate);

                            //        break;
                            //    case 1: strPicFormat = "TIFF"; strResult = myClass.DoIccUsm(strTempPath, destFileName, true, true, iccName, false, 0, 0, 0, ref strPicFormat, ref strInputIcc, ref intRatate);
                            //        break;
                            //}

                            psApp.AddICC(iccName, strTempPath, destFileName);

                            if (strResult == destFileName)
                            {
                                UPTLab("成功加载ICC文件!");
                            }
                            else
                            {
                                //加载ICC失败
                                UPTLab("加载ICC文件失败!" + strResult);
                                throw new Exception("加载ICC文件失败!" + strResult);
                            }
                        }
                        catch (Exception ex)
                        {
                            throw new Exception("加载ICC文件错误" + ex.Message);
                        }
                        finally
                        {
                            try
                            {
                                File.Delete(strTempPath);//删除保存到C盘的零时的图片文件
                            }
                            catch { }
                        }
                    }
                    else   //用LEADTOOLS加载ICC
                    {
                        if (File.Exists(board.BoardBaseInfo.IccPath))
                        {
                            try
                            {
                                IccProfileExtended iccProfile = new IccProfileExtended(board.BoardBaseInfo.IccPath);
                                iccProfile.WriteToImage(destFileName, destImage.PageCount);

                            }
                            catch (Exception ef)
                            {
                                UPTLab("加载ICC文件错误:" + ef.Message);
                                throw new Exception("加载ICC文件错误" + ef.Message);
                            }
                        }
                    }
                }
                #endregion

                destImage.Dispose();
                RasterCodecs.Shutdown();

                UPTLab("生成完成：" + destFileName);
                UPTPgro(1, 0);//进度条
                UPTListView(board.BoardBaseInfo.BoardId, destFileName, DateTime.Now, 1);
                _mainBLL.MakeBigPicSusscess(board.BoardBaseInfo.BoardId, destFileName);//生成成功后修改大板的状态  
                UPTLab("更新数据库成功");
                ProductPicCount++;
                UplblCount(ProductPicCount.ToString() + "张");


            }
            catch (Exception ex1)
            {
                UPTLab("错误：" + ex1.Message + "  " + destFileName);
                UPTListView(board.BoardBaseInfo.BoardId, ex1.Message + "," + errText, DateTime.Now, 0);
                //errText = "生成大图错误"+ex1.Message;
                _mainBLL.SetBoardStatus(board.BoardBaseInfo.BoardId, (int)EnumBoardStatus.Error, errText);
            }
            finally
            {
                errText = "";
            }
        }
        /// <summary>
        /// 竖版用获取图片
        /// </summary>
        /// <param name="picInfo"></param>
        /// <param name="codes"></param>
        /// <param name="board"></param>
        /// <returns></returns>
        private RasterImage CreatePicImgV(PhotoInfo_ProductBigPic picInfo, RasterCodecs codes, BoardInfo_ProductBigPic board)
        {
            UPTLab("正在加载图片...");
            RasterImage smallPicImage = null;
            string temFile = Application.StartupPath + "\\tem.tif";
            try
            {
                if (File.Exists(temFile))
                {
                    File.Delete(temFile);
                }
            }
            catch { }

            SizeCommand command = new SizeCommand();//改变大小,因为在分配打印机时由于四舍五入的原因改变过图像的大小


            string inPath = picInfo.PicPath;
            if (!picInfo.IsWhirl)
            {
                if (picInfo.PixWidth >= 10000 || picInfo.PixHeight >= 10000)
                {
                    string ExeFilePath = Application.StartupPath + "\\RotateImage.exe";
                    UPTLab("正在旋转......" + inPath);


                    using (System.Diagnostics.Process pExecuteEXE = new System.Diagnostics.Process())
                    {
                        pExecuteEXE.StartInfo.FileName = ExeFilePath;

                        pExecuteEXE.StartInfo.Arguments = inPath + "*" + temFile + "*" + picInfo.PixHeight + "*" + picInfo.PixWidth;

                        pExecuteEXE.Start();
                        pExecuteEXE.WaitForExit();
                    }

                    if (!File.Exists(temFile))
                    {
                        throw new Exception("旋转暂存文件读取失败EX" + inPath);
                    }
                    smallPicImage = codes.Load(temFile);
                    command.Width = picInfo.PixHeight;
                    command.Height = picInfo.PixWidth;
                    UPTLab("正在调整大小..." + inPath);
                    command.Flags = ReSizeModel(smallPicImage.Width, smallPicImage.Height, command.Width, command.Height);
                    command.Run(smallPicImage);
                }
                else
                {

                    UPTLab("正在调整大小..." + inPath);
                    smallPicImage = codes.Load(picInfo.PicPath);
                    command.Width = picInfo.PixWidth;
                    command.Height = picInfo.PixHeight;

                    command.Flags = ReSizeModel(smallPicImage.Width, smallPicImage.Height, command.Width, command.Height);
                    command.Run(smallPicImage);
                    UPTLab("正在旋转..." + inPath);

                    RotateCommand rc = new RotateCommand();

                    rc.Angle = 270 * 100;
                    rc.FillColor = new RasterColor(255, 255, 255);
                    rc.Flags = RotateCommandFlags.Resize;

                    rc.Run(smallPicImage);

                }

            }
            else
            {
                ///不需要旋转
                UPTLab("正在调整大小..." + inPath);
                smallPicImage = codes.Load(picInfo.PicPath);
                command.Width = picInfo.PixWidth;
                command.Height = picInfo.PixHeight;

                command.Flags = ReSizeModel(smallPicImage.Width, smallPicImage.Height, command.Width, command.Height);
                command.Run(smallPicImage);

            }



            UPTLab("正在调整图片模式...");
            if (smallPicImage.BitsPerPixel != 24)//判断是否灰度
            {
                ColorResolutionCommand colorRes = new ColorResolutionCommand();
                colorRes.Mode = ColorResolutionCommandMode.InPlace;
                colorRes.BitsPerPixel = 24;
                colorRes.DitheringMethod = RasterDitheringMethod.None;
                colorRes.PaletteFlags = ColorResolutionCommandPaletteFlags.Fixed;
                colorRes.Colors = 0;
                colorRes.Run(smallPicImage);

            }

            return smallPicImage;
        }
        private void DrowPicLine(ref  RasterImage rstImg, Color lineColor)
        {
            //RasterCodecs codecs = new RasterCodecs();
            RasterImage leftLine = new RasterImage(
                              RasterMemoryFlags.Conventional,
                              1,//+1
                              rstImg.Height,
                              24,
                              RasterByteOrder.Bgr,
                              RasterViewPerspective.BottomLeft,
                              null,
                              IntPtr.Zero,
                              0);
            FillCommand fcommandW = new FillCommand();
            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(leftLine);
            RasterImage RightLine = new RasterImage(
                             RasterMemoryFlags.Conventional,
                             1,//+1
                             rstImg.Height,
                             24,
                             RasterByteOrder.Bgr,
                             RasterViewPerspective.BottomLeft,
                             null,
                             IntPtr.Zero,
                             0);

            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(RightLine);
            RasterImage TopLine = new RasterImage(
                            RasterMemoryFlags.Conventional,
                            rstImg.Width,//+1
                            1,
                            24,
                            RasterByteOrder.Bgr,
                            RasterViewPerspective.BottomLeft,
                            null,
                            IntPtr.Zero,
                            0);
            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(TopLine);
            RasterImage BottomLine = new RasterImage(
                            RasterMemoryFlags.Conventional,
                            rstImg.Width,//+1
                            1,
                            24,
                            RasterByteOrder.Bgr,
                            RasterViewPerspective.BottomLeft,
                            null,
                            IntPtr.Zero,
                            0);
            fcommandW.Color = new RasterColor(lineColor.R, lineColor.G, lineColor.B);
            fcommandW.Run(BottomLine);
            CombineFastCommand cfcLine = new CombineFastCommand();
            cfcLine.SourcePoint = Point.Empty;
            cfcLine.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            cfcLine.DestinationImage = rstImg;

            cfcLine.DestinationRectangle = new Rectangle(0, 0, leftLine.Width, leftLine.Height);
            cfcLine.Run(leftLine);

            cfcLine.DestinationRectangle = new Rectangle(rstImg.Width - 1, 0, RightLine.Width, RightLine.Height);
            cfcLine.Run(RightLine);

            cfcLine.DestinationRectangle = new Rectangle(0, 0, TopLine.Width, TopLine.Height);
            cfcLine.Run(TopLine);

            cfcLine.DestinationRectangle = new Rectangle(0, rstImg.Height - 1, BottomLine.Width, BottomLine.Height);
            cfcLine.Run(BottomLine);



        }
        private RasterImage GetColorBlockTextBackcolor(int orderProductId)//根据产品得到相应的色块
        {
            RasterImage destImage = new RasterImage(
                      RasterMemoryFlags.Conventional,
                      COLORBLOCKWIDTH,
                      BARCODEHEIDHT,
                      24,
                      RasterByteOrder.Bgr,
                      RasterViewPerspective.BottomLeft,
                      null,
                      IntPtr.Zero,
                      0);

            int colorNum = orderProductId % 30;
            FillCommand fcommand = new FillCommand();
            RasterColor color = GetColor(colorNum);
            fcommand.Color = color;
            fcommand.Run(destImage);


            RasterImage frontImage = new RasterImage(
             RasterMemoryFlags.Conventional,
             25,
             25,
             24,
             RasterByteOrder.Bgr,
             RasterViewPerspective.BottomLeft,
             null,
             IntPtr.Zero,
             0);
            //FillCommand fcommand = new FillCommand();
            RasterColor colorWithe = new RasterColor(255, 255, 255);
            fcommand.Color = colorWithe;
            fcommand.Run(frontImage);

            CombineFastCommand combineFastCommand = new CombineFastCommand();
            combineFastCommand.DestinationImage = destImage;
            combineFastCommand.DestinationRectangle = new Rectangle(0, 0, frontImage.Width, frontImage.Height);
            combineFastCommand.Flags = CombineFastCommandFlags.OperationAdd | CombineFastCommandFlags.Destination0;
            combineFastCommand.Run(frontImage);

            DrawSharp(orderProductId, Color.FromArgb(0, color.R, color.G, color.B), destImage);
           


            return destImage;
        }
        private RasterImage CreateMidImgV(PhotoInfo_ProductBigPic picInfo)
        {
            int midPicWidth = 0, midPicHeight = 0;//中间图的宽高
            switch (picInfo.BarCodeStatus)
            {
                case (int)PhotoBarCodeStatus.RightOrLeft://条码在下方
                    if (!picInfo.IsWhirl)//旋转
                    {
                        midPicWidth = picInfo.PixHeight;
                        midPicHeight = picInfo.PixWidth + BARCODEHEIDHT;
                    }
                    else
                    {
                        midPicWidth = picInfo.PixWidth;
                        midPicHeight = picInfo.PixHeight + BARCODEHEIDHT;
                    }
                    break;
                case (int)PhotoBarCodeStatus.TopOrBottom://条码在右边
                    if (!picInfo.IsWhirl)
                    {
                        midPicWidth = picInfo.PixHeight + BARCODEHEIDHT;
                        midPicHeight = picInfo.PixWidth;
                    }
                    else
                    {
                        midPicWidth = picInfo.PixWidth + BARCODEHEIDHT;
                        midPicHeight = picInfo.PixHeight;
                    }
                    break;
                case (int)PhotoBarCodeStatus.NoBarCode: //无条码
                    if (!picInfo.IsWhirl)
                    {
                        midPicWidth = picInfo.PixHeight;
                        midPicHeight = picInfo.PixWidth;
                    }
                    else
                    {
                        midPicWidth = picInfo.PixWidth;
                        midPicHeight = picInfo.PixHeight;
                    }
                    break;
            }
            RasterImage midImg = new RasterImage(RasterMemoryFlags.Conventional, midPicWidth, midPicHeight, 24, RasterByteOrder.Bgr, RasterViewPerspective.BottomLeft, null, IntPtr.Zero, 0);

            FillCommand midfcommand = new FillCommand();//填充画布

            midfcommand.Color = new RasterColor(255, 255, 255);
            midfcommand.Run(midImg);

            return midImg;
        }
        private RasterImage CreateBarCodeImg(PhotoInfo_ProductBigPic picInfo, RasterImage midImageTmp, BoardInfo_ProductBigPic board, out Color BackColor)
        {
            int barCodeImageWidth;//条码图片的宽度,高度是固定的，因为在建图片是“横向建立”
            RasterImage barcodeImageTemp;
            if (picInfo.BarCodeStatus == (int)PhotoBarCodeStatus.TopOrBottom)//左边、右边放条码
            {
                barCodeImageWidth = midImageTmp.Height;
            }
            else
            {
                barCodeImageWidth = midImageTmp.Width;
            }

            barcodeImageTemp = new RasterImage(
                                                        RasterMemoryFlags.Conventional,
                                                        barCodeImageWidth,
                                                        BARCODEHEIDHT,
                                                        24,
                                                        RasterByteOrder.Bgr,
                                                        RasterViewPerspective.BottomLeft,
                                                        null,
                                                        IntPtr.Zero,
                                                        0);


            FillCommand fcBarcode = new FillCommand();
            fcBarcode.Color = new RasterColor(255, 255, 255);
            barcodeImageTemp.XResolution = board.BoardBaseInfo.DPI;
            barcodeImageTemp.YResolution = board.BoardBaseInfo.DPI;
            fcBarcode.Run(barcodeImageTemp);

            FillCommand midfcommand = new FillCommand();//填充画布

            midfcommand.Color = new RasterColor(255, 255, 255);
            //if (DateTransfer.PhotoRemarkFlag == 1)
            //{
            //    int cInt = picInfo.OrderProductId % 30;
            //    RasterColor color = GetColor(cInt);
            //    midfcommand.Color = color;
            //    BackColor = Color.FromArgb(color.R, color.G, color.B);
            //}
            //else
            //{
                midfcommand.Color = new RasterColor(255, 255, 255);
                BackColor = Color.FromArgb(255, 255, 255);
            //}

            midfcommand.Run(barcodeImageTemp);
            return barcodeImageTemp;
        }
        public static bool WrtieTextEn(StringBuilder sText, string sFile)
        {
            StreamWriter sw = new StreamWriter(sFile, false, Encoding.Default);
            try
            {
                string filePath = sFile;
                if (File.Exists(filePath))
                {
                    //sw = File.AppendAllText(sFile, sText.ToString(), Encoding.ASCII) ;

                    sw.WriteLine(sText);
                }
                else
                {
                    //sw = File.CreateText(sFile);
                    sw.WriteLine(sText);
                }
                //sw.Close();
                return true;
            }
            catch (Exception e)
            {
                string a = e.ToString();
                WriteLogForCheck.WriteLogFile("保存裁切文件错误"+a);
                return false;
            }
            finally
            {
                sw.Close();
            }
        }
        RasterSizeFlags ReSizeModel(int srcWidth, int srcHeight, int toWidth, int toHeigth)
        {
            RasterSizeFlags rtnFlag = RasterSizeFlags.Resample;
            //if (srcWidth >= toWidth || srcHeight >= toHeigth)
            //{
            //    rtnFlag = RasterSizeFlags.Resample;
            //}
            //else
            //{
            //    rtnFlag = RasterSizeFlags.Bicubic;
            //}
            rtnFlag = RasterSizeFlags.Bicubic;
            return rtnFlag;
        }
    }
}
